#include <SDL2/SDL_syswm.h>

#include "kill.h"
#include "exit_status.h"
#include "sdl_data.h"

#ifdef _WIN32
	#include <Windows.h>
	#include <Dwmapi.h>

	static void config_transparent(const SDL_SysWMinfo* info) {
		HWND handle = info->info.win.window;

		DWM_BLURBEHIND bb = { 0 };
		bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
		bb.fEnable = TRUE;
		bb.hRgnBlur = CreateRectRgn(0, 0, 1, 1);
		DwmEnableBlurBehindWindow(handle, &bb);
	}

	static void config_overlay(const SDL_SysWMinfo *info) {
		HWND handle = info->info.win.window;
		SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

		LONG cur_style = GetWindowLong(handle, GWL_EXSTYLE);
		SetWindowLong(handle, GWL_EXSTYLE, cur_style | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_NOACTIVATE);
	}
#else
	#error glassdrop does not currently support non-windows systems.
#endif

void os_config() {
	SDL_SysWMinfo main_info;
	SDL_VERSION(&main_info.version);

	SDL_SysWMinfo control_info;
	SDL_VERSION(&control_info.version);

	if (!SDL_GetWindowWMInfo(main_window, &main_info)) {
		kill_sdl("Could not get main system info", EX_ERR_SDL_GET_OS_INFO);
	}

	if (!SDL_GetWindowWMInfo(control_window, &control_info)) {
		kill_sdl("Could not get control system info", EX_ERR_SDL_GET_OS_INFO);
	}


	config_transparent(&main_info);
	config_transparent(&control_info);

	config_overlay(&main_info);

}